home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Macintosh Programmer’s Workshop / MPW 3.1 / MPW / Interfaces / CIncludes / StdIO.h < prev    next >
Text File  |  1990-12-13  |  5KB  |  248 lines

  1. /*
  2.  *    StdIO.h -- Standard C I/O Package
  3.  *    Modified for use with Macintosh C
  4.  *    Apple Computer, Inc.  1985-1988
  5.  *
  6.  *    Copyright American Telephone & Telegraph
  7.  *    Used with permission, Apple Computer Inc. (1985)
  8.  *    All rights reserved.
  9.  */
  10.  
  11. #ifndef __STDIO__
  12. #define __STDIO__
  13.  
  14. #ifndef __STDDEF__
  15. #include <StdDef.h>
  16. #endif __STDDEF__
  17.  
  18. #ifndef __STDARG__
  19. #include <StdArg.h>
  20. #endif __STDARG__
  21.  
  22.  
  23. /*
  24.  *    The basic data structure for a stream is the FILE.
  25.  */
  26.  
  27. typedef struct {
  28.     int             _cnt;
  29.     unsigned char    *_ptr;
  30.     unsigned char    *_base;
  31.     unsigned char    *_end;
  32.     unsigned short    _size;
  33.     unsigned short    _flag;
  34.     unsigned short    _file;
  35. } FILE;
  36.  
  37.  
  38. /*
  39.  *    fpos_t is a type that can express any position in a file.  A file's
  40.  *    end-of-file marker has type fpos_t.
  41.  */
  42.  
  43. typedef long fpos_t;
  44.  
  45.  
  46. /*
  47.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  48.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  49.  */
  50.  
  51. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  52. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  53. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  54. #define _IONBF        (1<<2)        /* no buffering */
  55. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  56. #define _IOEOF        (1<<4)
  57. #define _IOERR        (1<<5)
  58. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  59. #define _IORW        (1<<7)        /* Enable read/write access */
  60. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  61. #define _IOBINARY    (1<<9)        /* Binary stream */
  62.  
  63.  
  64. /*
  65.  *    Default file buffer sizes used by setbuf() and setvbuf().
  66.  */
  67.  
  68. #define BUFSIZ    1024            /* default file buffer size */
  69. #define _LBFSIZ  100            /* Line buffer size */
  70.  
  71.  
  72. /*
  73.  *    The standard end-of-file indicator.
  74.  */
  75.  
  76. #define EOF        (-1)
  77.  
  78.  
  79. /*
  80.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  81.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  82.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  83.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  84.  *    of digits, all determined at runtime.
  85.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  86.  */
  87.  
  88. #define L_tmpnam    14
  89. #define TMP_MAX        17576
  90.  
  91.  
  92. /*
  93.  *    The minimum number of files that a program is guaranteed to be able to have
  94.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  95.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  96.  *    64K ROM, 128K Macintosh        12 files
  97.  *    64K ROM, 512K Macintosh        40 files
  98.  *    128K ROM                    40 files per volume
  99.  */
  100.  
  101. #define FOPEN_MAX    12
  102.  
  103.  
  104. /*
  105.  *    Maximum length of a file name, including a trailing zero byte.
  106.  */
  107.  
  108. #define FILENAME_MAX    32
  109.  
  110.  
  111. /*
  112.  *    For use by fseek():
  113.  */
  114.  
  115. #define SEEK_CUR    1
  116. #define SEEK_END    2
  117. #define SEEK_SET    0
  118.  
  119.  
  120. /*
  121.  *    The standard predefined streams.
  122.  */
  123.  
  124. #define stdin        (&_iob[0])
  125. #define stdout        (&_iob[1])
  126. #define stderr        (&_iob[2])
  127.  
  128.  
  129. #ifdef __safe_link
  130. extern "C" {
  131. #endif
  132.  
  133. /*
  134.  *    Operations on files
  135.  */
  136.  
  137. int remove (const char *);
  138. int rename (const char *, const char *);
  139. FILE *tmpfile (void);
  140. char *tmpnam (char *);
  141.  
  142.  
  143. /*
  144.  *    File access functions
  145.  */
  146.  
  147. int fclose (FILE *);
  148. int fflush (FILE *);
  149. FILE *fopen (const char *, const char *);
  150. FILE *freopen (const char *, const char *, FILE *);
  151. void setbuf (FILE *, char *);
  152. int setvbuf (FILE *, char *, int, size_t);
  153.  
  154.  
  155. /*
  156.  *    Formatted input/output functions
  157.  */
  158.  
  159. int fprintf (FILE *, const char *, ...);
  160. int fscanf (FILE *, const char *, ...);
  161. int printf (const char *, ...);
  162. int scanf (const char *, ...);
  163. int sprintf (char *, const char *, ...);
  164. int sscanf (const char *, const char *, ...);
  165. int vfprintf (FILE *, const char *, va_list);
  166. int vprintf (const char *, va_list);
  167. int vsprintf (char *, const char *, va_list);
  168.  
  169.  
  170. /*
  171.  *    Character input/output functions and macros
  172.  */
  173.  
  174. int fgetc (FILE *);
  175. char *fgets (char *, int, FILE *);
  176. int fputc (int, FILE *);
  177. int fputs (const char *, FILE *);
  178. int getc (FILE *stream);
  179. int getchar (void);
  180. char *gets (char *);
  181. int putc (int c, FILE *stream);
  182. int putchar (int c);
  183. int puts (const char *);
  184. int ungetc (int, FILE *);
  185.  
  186. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  187. #define getchar()    getc(stdin)
  188. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  189.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  190.                         _flsbuf((unsigned char) (x), (p)))
  191. #define putchar(x)    putc((x), stdout)
  192.  
  193.  
  194. /*
  195.  *    Direct input/output functions
  196.  */
  197.  
  198. size_t fread (void *, size_t, size_t, FILE *);
  199. size_t fwrite (const void *, size_t, size_t, FILE *);
  200.  
  201.  
  202. /*
  203.  *    File positioning functions
  204.  */
  205.  
  206. int fgetpos (FILE *, fpos_t *);
  207. int fseek (FILE *, long int, int);
  208. int fsetpos (FILE *, const fpos_t *);
  209. long int ftell (FILE *);
  210. void rewind (FILE *);
  211.  
  212.  
  213. /*
  214.  *    Error-handling functions and macros
  215.  */
  216.  
  217. void clearerr (FILE *stream);
  218. int feof (FILE *stream);
  219. int ferror (FILE *stream);
  220. void perror (const char *s);
  221.  
  222. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  223. #define feof(p)     ((p)->_flag & _IOEOF)
  224. #define ferror(p)    ((p)->_flag & _IOERR)
  225.  
  226.  
  227. /*
  228.  *    Non-ANSI extensions, and things used internally:
  229.  */
  230.  
  231. #define _NFILE      20
  232. extern FILE _iob[_NFILE];
  233. #define _bufend(p)    (p)->_end
  234. #define _bufsiz(p)    (p)->_size
  235. #define fileno(p)    (p)->_file
  236. FILE *fdopen (int, char *);
  237. int _filbuf (FILE *);
  238. int _flsbuf (int, FILE *);
  239. int getw (FILE *);
  240. int putw (int, FILE *);
  241.  
  242. #ifdef __safe_link
  243. }
  244. #endif
  245.  
  246.  
  247. #endif __STDIO__
  248.